﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Application;
using MySqlConnection;

namespace Data
{
    public static class NewsData
    {
        public static List<VONews> GetAllNews()
        {
            List<VONews> allVONews = new List<VONews>();
            DBContainer dbCont = MySqlContext.DataContext;
            List<NewsClass> allNews = dbCont.GetAllNews();
            foreach (NewsClass news in allNews)
            {
                allVONews.Add(VOMapperNews.NewsInstanceFromData(news));
            }
            return allVONews;
        }

        public static void AddNews(VONews news)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            NewsClass newsObj = new NewsClass();
            newsObj.title = news.Title;
            newsObj.created = news.Created;
            newsObj.modified = news.Modified;
            newsObj.description = news.Description;
            dbCont.AddNews(newsObj);
        }

        public static void DeleteNews(string id)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            dbCont.DeleteNews(id);
        }

        public static VONews GetNewsById(string id)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            return VOMapperNews.NewsInstanceFromData(dbCont.GetNewsById(id));
        }
    }
}
